#import "XMConversationListHeaderView.h"
#import "RCConversationCell.h"
#import "RCloudImageView.h"
#import "RCConversationModel.h"


@interface XMConversationListHeaderView ()
@property (nonatomic, strong) UIView *replyView;
@property (nonatomic, strong) UIImageView *headImgView;
@property (nonatomic, strong) UILabel *titleLa;
@property (nonatomic, strong) UILabel *contentLa;
@property (nonatomic, strong) RCConversationCell *noticeCell;
@property (nonatomic, strong) RCConversationCell *systemCell;

@end

@implementation XMConversationListHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setCheckModel:(RCConversationModel *)checkModel {
    _checkModel = checkModel;
    checkModel.isTop = NO;
    checkModel.conversationTitle = @"审核通知";
    checkModel.cellBackgroundColor = UIColor.clearColor;
    checkModel.topCellBackgroundColor = UIColor.clearColor;
    checkModel.extend = @"";
    self.noticeCell.detailContentView.hidden = NO;
    self.noticeCell.intimacyLa.hidden = YES;
    [self.noticeCell setDataModel:checkModel];
}

- (void)setSystemModel:(RCConversationModel *)systemModel {
    _systemModel = systemModel;
    systemModel.isTop = NO;
    systemModel.conversationTitle = @"系统通知";
    systemModel.cellBackgroundColor = UIColor.clearColor;
    systemModel.topCellBackgroundColor = UIColor.clearColor;
    systemModel.extend = @"";
    self.systemCell.detailContentView.hidden = NO;
    self.systemCell.intimacyLa.hidden = YES;
    [self.systemCell setDataModel:systemModel];
}

#pragma mark - setupSubviews
- (void)setupSubviews {
    self.backgroundColor = [UIColor xm_colorWithHexString:@"#FFFFFF" alpha:1];
    RCConversationCell *cell = [[RCConversationCell alloc] initWithFrame:kFRAME(0, 0, kScreenWidth, 70)];
    cell.headerImageView.placeholderImage = kGetImage(@"msg_huodong");
    cell.statusView.hidden = YES;
    cell.intimacyLa.hidden = YES;
    cell.detailContentView.hidden = YES;
    cell.conversationTitle.text = @"活动通知";
    cell.messageContentLabel.text = @"";
    cell.cellBackgroundColor = UIColor.clearColor;
    cell.topCellBackgroundColor = UIColor.clearColor;
    cell.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapCell = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapNoticeCell)];
    [cell addGestureRecognizer:tapCell];
    
    [self addSubview:cell];
    self.noticeCell = cell;
    
    RCConversationCell *cell1 = [[RCConversationCell alloc] initWithFrame:kFRAME(0, 0, kScreenWidth, 70)];
    cell1.headerImageView.placeholderImage = kGetImage(@"msg_xitong");
    cell1.statusView.hidden = YES;
    cell1.intimacyLa.hidden = YES;
    cell1.detailContentView.hidden = YES;
    cell1.conversationTitle.text = @"系统通知";
    cell1.messageContentLabel.text = @"";
    cell1.cellBackgroundColor = UIColor.clearColor;
    cell1.topCellBackgroundColor = UIColor.clearColor;
    cell1.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapCell1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapNoticeCell1)];
    [cell1 addGestureRecognizer:tapCell1];
    [self addSubview:cell1];
    self.systemCell = cell1;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.noticeCell.frame = kFRAME(0, 0, kScreenWidth, 70);
    self.systemCell.frame = kFRAME(0, 70, kScreenWidth, 70);
}

- (void)tapNoticeCell {
    if (!self.checkModel) {
        RCConversationModel *model = [[RCConversationModel alloc] init];
        model.targetId = @"2";
        model.conversationType = ConversationType_SYSTEM;
        model.conversationTitle = @"活动通知";
        if (self.checkBlock) {
            self.checkBlock(model);
        }
    } else {
        if (self.checkBlock) {
            self.checkBlock(self.checkModel);
        }
    }
}

- (void)tapNoticeCell1 {
    if (!self.systemModel) {
        RCConversationModel *model = [[RCConversationModel alloc] init];
        model.targetId = @"1";
        model.conversationType = ConversationType_SYSTEM;
        model.conversationTitle = @"系统通知";
        if (self.checkBlock) {
            self.checkBlock(model);
        }
    } else {
        if (self.checkBlock) {
            self.checkBlock(self.systemModel);
        }
    }
}

@end
